if select(2, UnitClass("player")) ~= "HUNTER" then return end
local GetSpellInfo = GetSpellInfo
local UnitCreatureType = UnitCreatureType
local GetTrackingTexture = GetTrackingTexture
local IsEquippedItem = IsEquippedItem
local tonumber = tonumber
local string_match = string.match
local string_find = string.find
local string_lower = string.lower
local select = select

local trackingtypes = {	
	--Track Beasts
	 ["Interface\Icons\Ability_Tracking"] = true,
	--Track Demons
	["Interface\Icons\Spell_Shadow_SummonFelHunter"] = true,
	--Track Dragonkin
	["Interface\Icons\INV_Misc_Head_Dragon_01"] = true,
	--Track Elementals
	["Interface\Icons\Spell_Frost_SummonWaterElemental"] = true,
	--Track Giants
	["Interface\Icons\Ability_Racial_Avatar"] = true,
	--Track Humanoids
	["Interface\Icons\Spell_Holy_PrayerOfHealing"] = true,
	--Track Undead
	["Interface\Icons\Spell_Shadow_DarkSummoning"] = true,
 }
--Track Beasts, Sense Demons, Track Dragonkin, Track Elementals, Track Giants, Track Humanoids, Sense Undead
local tracking = string_lower(GetSpellInfo(1494) .. GetSpellInfo(5500) .. GetSpellInfo(19879) .. GetSpellInfo(19880) .. GetSpellInfo(19882) .. GetSpellInfo(19883) .. GetSpellInfo(5502))

function DrDamage:PlayerData()

	--General
	local piercingshots = GetSpellInfo(53234)
	self.Calculation["HUNTER"] = function( calculation, ActiveAuras, BuffTalentRanks, action, baseAction )
		if BuffTalentRanks["Rapid Killing"] and ActiveAuras["Rapid Killing"] then
			calculation.dmgM = calculation.dmgM * (1 + BuffTalentRanks["Rapid Killing"])
		end
		if ActiveAuras["Serpent Sting"] and BuffTalentRanks["Noxious Stings"] then
			calculation.dmgM = calculation.dmgM * (1 + BuffTalentRanks["Noxious Stings"])
		end
		if ActiveAuras["Freezing Trap"] or ActiveAuras["Frost Trap"] or ActiveAuras["Freezing Arrow"] then
			if BuffTalentRanks["Point of No Escape"] then
				calculation.critPerc = calculation.critPerc + BuffTalentRanks["Point of No Escape"]
			end
		end
		if ActiveAuras["Hunter's Mark"] and BuffTalentRanks["Marked for Death"] then
			calculation.dmgM = calculation.dmgM * (1 + BuffTalentRanks["Marked for Death"])
		end	
	
		if BuffTalentRanks["Improved Tracking"] and not calculation.subType == "Trap" and GetTrackingTexture() and trackingtypes[GetTrackingTexture()] then
			local target = UnitCreatureType("target")
			if target and string_find(tracking,string_lower(target)) then
				calculation.dmgM = calculation.dmgM * (1 + BuffTalentRanks["Improved Tracking"])
			end
		end
		if BuffTalentRanks["Piercing Shots"] then
			calculation.extraDamage = 0
			calculation.extraCrit = BuffTalentRanks["Piercing Shots"]
			calculation.extraChanceCrit = true
			calculation.extraTicks = 8
			calculation.extraName = piercingshots
		end		
	end
	--Talents
	local wildquiver = GetSpellInfo(53215)
	self.Calculation["Wild Quiver"] = function( calculation, value )
		calculation.extraDamage = 0
		calculation.extraWeaponDamage = 0.8
		calculation.extraChance = value
		calculation.extra_canCrit = true
		calculation.extraName = wildquiver
	end
	
	--Spell specific
	self.Calculation["Steady Shot"] = function( calculation, ActiveAuras, _, spell )
		local min, max = self:GetRangedBase()
		local spd = select(3,self:GetWeaponSpeed())
		local ammo = self:GetAmmoDmg()
		if spd then
			calculation.minDam = calculation.minDam + min/spd * 2.8 + ammo/spd * 2.8
			calculation.maxDam = calculation.maxDam + max/spd * 2.8 + ammo/spd * 2.8
		end
		if ActiveAuras["Dazed"] then
			calculation.minDam = calculation.minDam + 175
			calculation.maxDam = calculation.maxDam + 175
		end
		--Glyph of Steady Shot
		if self:HasGlyph(56826) and ActiveAuras["Serpent Sting"] then
			calculation.dmgM = calculation.dmgM * 1.1
		end
	end

	self.Calculation["Aimed Shot"] = function( calculation, ActiveAuras, BuffTalentRanks )
		if ActiveAuras["Improved Steady Shot"] and BuffTalentRanks["Improved Steady Shot"] then
			calculation.dmgM = calculation.dmgM + BuffTalentRanks["Improved Steady Shot"]
		end
		--Glyph of Trueshot Aura
		if self:HasGlyph(56842) and ActiveAuras["Trueshot Aura"] then
			calculation.critPerc = calculation.critPerc + 10
		end
		--Glyph of Aimed Shot
		if self:HasGlyph(56824) then
			calculation.cooldown = calculation.cooldown - 2		
		end
	end
	self.Calculation["Multi-Shot"] = function( calculation )
		--Gladiator's Chain Gauntlets
		if IsEquippedItem( 28335 ) or IsEquippedItem( 31961 ) or IsEquippedItem( 33665 ) then
			calculation.dmgM = calculation.dmgM * 1.05
		end
		--Glyph of Multi-Shot
		if self:HasGlyph(56836) then
			calculation.cooldown = calculation.cooldown - 1		
		end		
		
	end
	self.Calculation["Arcane Shot"] = function ( calculation, ActiveAuras, BuffTalentRanks )
		if ActiveAuras["Improved Steady Shot"] and BuffTalentRanks["Improved Steady Shot"] then
			calculation.dmgM = calculation.dmgM + BuffTalentRanks["Improved Steady Shot"]
		end
	end
	self.Calculation["Chimera Shot"] = function ( calculation, ActiveAuras, BuffTalentRanks )
		if ActiveAuras["Improved Steady Shot"] and BuffTalentRanks["Improved Steady Shot"] then
			calculation.dmgM = calculation.dmgM + BuffTalentRanks["Improved Steady Shot"]
		end
		if ActiveAuras["Serpent Sting"] then 
			--Modify Chimera tooltip to include damage on targets with Serpent Sting active
			local dmgtoadd = (1 + (BuffTalentRanks["Improved Stings"] or 0)) * (self:GetRAP() * 0.2 + select(ActiveAuras["Serpent Sting"], 20, 40, 80, 140, 210, 290, 385, 490, 555, 660, 990, 1210))
			calculation.minDam = calculation.minDam + 0.4 * dmgtoadd
			calculation.maxDam = calculation.maxDam + 0.4 * dmgtoadd
		end
		--Glyph of Chimera Shot
		if self:HasGlyph(63065) then
			calculation.cooldown = calculation.cooldown - 1		
		end			
	end
	self.Calculation["Explosive Shot"] = function ( calculation )
		--Glyph of Explosive Shot
		if self:HasGlyph(63066) then
			calculation.critPerc = calculation.critPerc + 4
		end
	end
	self.Calculation["Explosive Trap"] = function ( calculation )
		--Glyph of Explosive Trap
		if self:HasGlyph(63068) then
			calculation.NoCrits = false
			--TODO: Verify crit modifier
			calculation.critM = 1
		end
	end
	
	self.Calculation["Immolation Trap"] = function ( calculation )
		--Glyph of Immolation Trap
		if self:HasGlyph(56846) then
			calculation.eDuration = calculation.eDuration - 6
			calculation.dmgM = calculation.dmgM * 2
		end
	end
	self.Calculation["Serpent Sting"] = function ( calculation )
		--Glyph of Serpent Sting
		if self:HasGlyph(56832) then
			calculation.eDuration = calculation.eDuration + 6
		end
	end
	self.Calculation["Kill Shot"] = function ( calculation )
		--Glyph of Kill Shot
		if self:HasGlyph(63067) then
			calculation.cooldown = calculation.cooldown - 6	
		end
	end
	self.Calculation["Wyvern Sting"] = function ( calculation )
		--Glyph of Wyvern Sting
		if self:HasGlyph(56848) then
			calculation.cooldown = calculation.cooldown - 6	
		end
	end	

	--Set Bonuses
	self.SetBonuses["T8"] = { 45360, 45361, 45362, 45363, 45364, 46141, 46142, 46143, 46144, 46145 }
	
	self.SetBonuses["Serpent Sting"] = function( calculation, ActiveAuras )
		if self:GetSetAmount("T8") >= 2 then
			calculation.dmgM = calculation.dmgM * 1.1
		end
	end

--AURA
--Player
	--Rapid Killing
	self.PlayerAura[GetSpellInfo(35098)] = { ActiveAura = "Rapid Killing" }
	--Improved Steady Shot
	self.PlayerAura[GetSpellInfo(53220)] = { ActiveAura = "Improved Steady Shot" }
	--Trueshot Aura
	self.PlayerAura[GetSpellInfo(31519)] = { ActiveAura = "Trueshot Aura" }
	--The Beast Within
	--self.PlayerAura[GetSpellInfo(34471)] = { Value = 0.1 }
--Target
	--Freezing Trap
	self.TargetAura[GetSpellInfo(3355)] = { ActiveAura = "Freezing Trap" }
	--Frost Trap
	self.TargetAura[GetSpellInfo(13810)] = { ActiveAura = "Frost Trap" }
	--Freezing Arrow
	self.TargetAura[GetSpellInfo(60210)] = { ActiveAura = "Freezing Arrow" }
	--Dazed
	self.TargetAura[GetSpellInfo(1604)] = { ActiveAura = "Dazed", Spells = GetSpellInfo(34120) }
	--Black Arrow
	self.TargetAura[GetSpellInfo(63672)] = { Value = 0.06 }
	--Serpent Sting
	self.TargetAura[GetSpellInfo(1978)] = { ActiveAura = "Serpent Sting", Ranks = 12 }
	--Hunter's Mark
	self.TargetAura[GetSpellInfo(1130)] = { School = "Ranged", ModType = "Special" }
	--Sniper Training
	self.TargetAura[GetSpellInfo(53302)] = { Spells = { [GetSpellInfo(56641)] = true, [GetSpellInfo(19434)] = true, [GetSpellInfo(3674)] = true, [GetSpellInfo(53301)] = true }, Value = 0.02, Ranks = 3 }
--Special aura handling	
	--Hunter's Mark
	self.Calculation[GetSpellInfo(1130)] = function( calculation, ActiveAuras, BuffTalentRanks, _, _, _, rank )
		rank = rank and tonumber(string_match(rank,"%d+")) or 5
		--Glyph of Hunter's Mark
		calculation.AP = calculation.AP + (select(rank, 20, 45, 75, 110, 500)) * (1 + (BuffTalentRanks["Improved Hunter's Mark"] or 0) + (self:HasGlyph(56829) and 0.2 or 0))
		ActiveAuras["Hunter's Mark"] = true
	end	
	
	self.spellInfo = {
		[GetSpellInfo(75)] = {
			["Name"] = "Auto Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 1, NoNormalization = true, AutoShot = true },
			[1] = { 0 },
		},
		[GetSpellInfo(3044)] = {
			["Name"] = "Arcane Shot",
			[0] = { School = { "Ranged", "Arcane", "Shot" }, Cooldown = 6, APBonus = 0.15 },
			[1] = { 15 },
			[2] = { 23 },
			[3] = { 36 },
			[4] = { 65 },
			[5] = { 91 },
			[6] = { 125 },
			[7] = { 158 },
			[8] = { 200 },
			[9] = { 273 },
			[10] = { 402 },
			[11] = { 492 },
		},
		[GetSpellInfo(19434)] = {
			["Name"] = "Aimed Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 1, Cooldown = 10, BleedExtra = true, },
			[1] = { 5 },
			[2] = { 35 },
			[3] = { 55 },
			[4] = { 90 },
			[5] = { 110 },
			[6] = { 150 },
			[7] = { 205 },
			[8] = { 345 },
			[9] = { 408 },
		},
		[GetSpellInfo(2643)] = {
			["Name"] = "Multi-Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 1, Cooldown = 10 },
			[1] = { 0 },
			[2] = { 40 },
			[3] = { 80 },
			[4] = { 120 },
			[5] = { 150 },
			[6] = { 205 },
			[7] = { 333 },
			[8] = { 408 },
		},
		[GetSpellInfo(19503)] = {
			["Name"] = "Scatter Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 0.5, Cooldown = 30 },
			[1] = { 0 },
		},
		[GetSpellInfo(34490)] = {
			["Name"] = "Silencing Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 0.5, Cooldown = 20 },
			[1] = { 0 },
		},
		[GetSpellInfo(34120)] = { 
			["Name"] = "Steady Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, castTime = 2, APBonus = 0.1, DPSrg = true, BleedExtra = true },
			[1] = { 45 },
			[2] = { 108 },
			[3] = { 198 },
			[4] = { 252 },
		},
		[GetSpellInfo(1510)] = {
			["Name"] = "Volley",
			[0] = { School = { "Ranged", "Arcane" }, eDuration = 6, Ticks = 1 },
			[1] = { 312 },
			[2] = { 474 },
			[3] = { 630 },
			[4] = { 1008 },
			[5] = { 1740 },
			[6] = { 2118 },
		},
		[GetSpellInfo(53351)] = {
			["Name"] = "Kill Shot",
			[0] = { School = { "Ranged", "Physical", "Shot" }, WeaponDamage = 2, APBonus = 0.4, Cooldown = 15 },
			[1] = { 410 },
			[2] = { 500 },
			[3] = { 650 },
		},
		[GetSpellInfo(53209)] = {
			["Name"] = "Chimera Shot",
			[0] = { School = { "Ranged", "Nature", "Shot" }, WeaponDamage = 1.25, Cooldown = 10, BleedExtra = true },
			[1] = { 0 },
		},
		[GetSpellInfo(13795)] = {
			["Name"] = "Immolation Trap",
			[0] = { School = { "Ranged", "Fire", "Trap" }, Unresistable = true, APBonus = 0.1, NoCrits = true, eDuration = 15, Ticks = 3, Cooldown = 30, NoWeapon = true },
			[1] = { 105 },
			[2] = { 215 },
			[3] = { 340 },
			[4] = { 510 },
			[5] = { 690 },
			[6] = { 985 },
			[7] = { 1540 },
			[8] = { 1885 },
		},
		[GetSpellInfo(13813)] = {
			["Name"] = "Explosive Trap",
			[0] = { School = { "Ranged", "Fire", "Trap" }, Unresistable = true, APBonus = 0.1, NoCrits = true, ExtraDamage = 0, E_eDuration = 20, E_Ticks = 2, Cooldown = 30, NoWeapon = true },
			[1] = { 100, 130, Extra = 150 },
			[2] = { 139, 187, Extra = 240 },
			[3] = { 201, 257, Extra = 330 },
			[4] = { 263, 337, Extra = 450 },
			[5] = { 434, 556, Extra = 740 },
			[6] = { 523, 671, Extra = 900 },
		},		
		[GetSpellInfo(19386)] = {
			["Name"] = "Wyvern Sting",
			[0] = { School = { "Ranged", "Nature" }, NoCrits = true, eDuration = 6 },
			[1] = { 300 },
			[2] = { 420 },
			[3] = { 600 },
			[4] = { 942 },
			[5] = { 2082 },
			[6] = { 2460 },
		},
		[GetSpellInfo(1978)] = {
			["Name"] = "Serpent Sting",
			[0] = { School = { "Ranged", "Nature" }, APBonus = 0.2, NoCrits = true, eDuration = 15, Ticks = 3 },
			[1] = { 20 },
			[2] = { 40 },
			[3] = { 80 },
			[4] = { 140 },
			[5] = { 210 },
			[6] = { 290 },
			[7] = { 385 },
			[8] = { 490 },
			[9] = { 555 },
			[10] = { 660 },
			[11] = { 990 },
			[12] = { 1210 },
		},		
		[GetSpellInfo(2973)] = {
			["Name"] = "Raptor Strike",
			[0] = { WeaponDamage = 1, Cooldown = 6, NextMelee = true, NoNormalization = true },
			[1] = { 5 },
			[2] = { 11 },
			[3] = { 21 },
			[4] = { 34 },
			[5] = { 50 },
			[6] = { 80 },
			[7] = { 110 },
			[8] = { 140 },
			[9] = { 170 },
			[10] = { 275 },
			[11] = { 335 },
		},
		[GetSpellInfo(1495)] = {
			["Name"] = "Mongoose Bite",
			[0] = { Cooldown = 5, APBonus = 0.2, NoWeapon = true },
			[1] = { 25 },
			[2] = { 45 },
			[3] = { 75 },
			[4] = { 115 },
			[5] = { 150 },
			[6] = { 280 },
		},
		[GetSpellInfo(19306)] = {
			["Name"] = "Counterattack",
			[0] = { Cooldown = 5, APBonus = 0.2, NoWeapon = true },
			[1] = { 48 },
			[2] = { 84 },
			[3] = { 132 },
			[4] = { 196 },
			[5] = { 288 },
			[6] = { 342 },
		},
		[GetSpellInfo(3674)] = {
			["Name"] = "Black Arrow",
			[0] = { School = { "Ranged", "Shadow" }, Cooldown = 30, APBonus = 0.1, NoCrits = true, eDuration = 15, Ticks = 3 },
			[1] = { 785 },
			[2] = { 940 },
			[3] = { 1205 },
			[4] = { 1480 },
			[5] = { 2240 },
			[6] = { 2765 },
		},
		[GetSpellInfo(53301)] = {
			["Name"] = "Explosive Shot",
			[0] = { School = { "Ranged", "Fire", "Shot" }, APBonus = 0.14, Cooldown = 6, Hits = 3 },
			[1] = { 144, 172 },
			[2] = { 221, 265 },
			[3] = { 325, 391 },
			[4] = { 386, 464 },
		},
	}
	self.talentInfo = {
		--Beast Mastery:
		--Ferocious Inspiration (the rest is handled by API)
		[GetSpellInfo(34455)] = {	[1] = { Effect = 0.03, Spells = "Arcane Shot" }, },
		
		--Marksmanship:
		--Focused Aim
		[GetSpellInfo(53620)] = { 	[1] = { Effect = 1, Spells = "All", ModType = "hitPerc", }, },
		--Improved Hunter's Mark
		[GetSpellInfo(19421)] = {	[1] = { Effect = 0.1, Spells = "Ranged", ModType = "Improved Hunter's Mark" }, },
		--Mortal Shots
		[GetSpellInfo(19485)] = {	[1] = { Effect = 0.06, Spells = "Ranged", Specials = true, ModType = "critM" }, },
		--Improved Arcane Shot
		[GetSpellInfo(19454)] = {	[1] = { Effect = 0.05, Spells = "Arcane Shot" }, },
		--Rapid Killing
		[GetSpellInfo(34948)] = {	[1] = { Effect = 0.1, Spells = { "Aimed Shot", "Arcane Shot", "Chimera Shot" }, ModType = "Rapid Killing"  }, },
		--Improved Stings
		[GetSpellInfo(19464)] = {	[1] = { Effect = 0.1, Spells = { "Serpent Sting", "Wyvern Sting" } }, 
						[2] = { Effect = 0.1, Spells = "Chimera Shot", ModType = "Improved Stings" } },		
		--Barrage
		[GetSpellInfo(19461)] = {	[1] = { Effect = 0.04, Spells = { "Aimed Shot", "Multi-Shot", "Volley" }, }, },
		--Piercing Shots
		[GetSpellInfo(53234)] = {	[1] = { Effect = 0.1, Spells = { "Aimed Shot", "Steady Shot", "Chimera Shot" }, ModType = "Piercing Shots" }, },
		--Ranged Weapon Specialization
		[GetSpellInfo(19507)] = {	[1] = { Effect = { 0.01, 0.03, 0.05 }, Spells = { "Shot", "Volley" } }, },
		--Improved Barrage
		[GetSpellInfo(35104)] = {	[1] = { Effect = 4, Spells = { "Aimed Shot", "Multi-Shot" }, ModType = "critPerc" }, },
		--Wild Quiver
		[GetSpellInfo(53215)] = {	[1] = { Effect = 0.04, Spells = "Auto Shot", ModType = "Wild Quiver" }, },
		--Improved Steady Shot
		[GetSpellInfo(53221)] = {	[1] = { Effect = 0.05, Spells = { "Aimed Shot", "Arcane Shot", "Chimera Shot" },  ModType = "Improved Steady Shot" }, },
		--Marked for Death
		[GetSpellInfo(53241)] = { 	[1] = { Effect = 0.01, Spells = "Shot", ModType = "Marked for Death" },
						[2] = { Effect = 0.02, Spells = { "Aimed Shot", "Arcane Shot", "Steady Shot", "Kill Shot", "Chimera Shot" }, ModType = "critM" }, },
		--Survival:
		--Improved Tracking
		[GetSpellInfo(52783)] = {	[1] = { Effect = 0.01, Spells = "Ranged", ModType = "Improved Tracking" }, },
		--Savage Strikes
		[GetSpellInfo(19159)] = {	[1] = { Effect = 10, Spells = { "Raptor Strike", "Mongoose Bite", "Counterattack" }, ModType = "critPerc" }, },
		--Trap Mastery
		[GetSpellInfo(19376)] = {	[1] = { Effect = 0.1, Spells = { "Immolation Trap", "Black Arrow" },  },
						[2] = { Effect = 0.1, Spells = "Explosive Trap", ModType = "dmgM_Extra" }, },
		--Survival Instincts
		[GetSpellInfo(34494)] = {	[1] = { Effect = 2, Spells = { "Arcane Shot", "Steady Shot", "Explosive Shot" }, ModType = "critPerc" }, }, 
		--T.N.T.
		[GetSpellInfo(56333)] = {	[1] = { Effect = 0.02, Spells = { "Explosive Shot", "Explosive Trap", "Immolation Trap", "Black Arrow" }, }, },
		--Resourcefulness
		[GetSpellInfo(34491)] = {	[1] = { Effect = -2, Spells = { "Explosive Trap", "Immolation Trap", "Black Arrow" }, ModType = "cooldown" }, },
		--Thrill of the Hunt
		[GetSpellInfo(34497)] = { 	[1] = { Effect = { 0.4*(1/3), 0.4*(2/3), 0.4 }, Spells = "Shot", ModType = "freeCrit" }, },
		--Noxious Stings
		[GetSpellInfo(53295)] = { 	[1] = { Effect = 0.01, Spells = "All", ModType = "Noxious Stings" }, },
		--Point of No Escape
		[GetSpellInfo(53298)] = {	[1] = { Effect = 3, Spells = "All", ModType = "Point of No Escape" }, },
		--Sniper Training (Kill Shot bonus only, rest handled elsewhere)
		[GetSpellInfo(53302)] = {	[1] = { Effect = 5, Spells = "Kill Shot", ModType = "critPerc" }, },
		
	}
end
